<template>
  <el-dialog
    :visible.sync="$attrs.visable"
    :width="width"
    :before-close="handleClose"
    append-to-body
  >
    <template slot="title">
      <span class="c_text2 f-15 fw-6 titlex">{{ title }}</span>
      <span class="c_primary commhover f-14 pl-12">
        <i class="el-icon-info"></i>
        如何添加小程序/视频号？
      </span>
    </template>
    <div class="flex materbox" :style="{height:height}">
      <div class="m_left">
        <el-tabs v-model="activeName" @tab-click="handleClick">
          <el-tab-pane label="企业素材库" name="1">
            <!-- <MaterialList
              v-if="activeName == 'first'"
              @selectItem="handleSelect"
            /> -->
          </el-tab-pane>
          <el-tab-pane label="个人素材库" name="2">
            <!-- <MaterialList
              v-if="activeName == 'second'"
              @selectItem="handleSelect"
            /> -->
          </el-tab-pane>
        </el-tabs>
        <MaterialList
          :materType='activeName'
          @selectItem="handleSelect"
        />
      </div>
      <div class="m_right">
        <div class="r_header pl-16">预览</div>
        <div class="r_content" v-if="selectMaterItem">
          <div
            v-for="(item, index) in selectMaterItem.list"
            :key="index"
            class="flex aligncenter chat-item p-10"
          >
            <div class="chat-dot">
              <span class="dot">{{ index + 1 }}</span>
            </div>
            <div class="chat-dot mr-10">
              <i
                v-if="item.checked"
                class="el-icon-success c_primary f-18 commhover"
                @click="handleChecked(item)"
              ></i>
              <i v-else class="el-icon-circle-check f-18 commhover" @click="handleChecked(item)"></i>
            </div>
            <template v-if="item.type == 1">
              <div class="textitem f-14">
                {{item.content}}
              </div>
            </template>
            <template v-if="item.type == 2">
              <img
                :src="item.content"
                alt=""
                class="imgitem"
              />
            </template>
          </div>
        </div>
      </div>
    </div>
    <span slot="footer" class="dialog-footer">
      <div class="flexbetween">
        <div class="f-14 c_text">
          <span class="pr-16">已选择素材:8</span> 
          <span class="">本次可导入上限:91</span> 
        </div>
        <div>
          <el-button size="small" @click="handleClose">取 消</el-button>
          <el-button size="small" @click="handleClose">导入并继续</el-button>
          <el-button size="small" type="primary" @click="handleSubmit">导 入</el-button>
        </div>
      </div>
    </span>
  </el-dialog>
</template>

<script>
import MaterialList from "./MaterialList.vue";
export default {
  data() {
    return {
      activeName: "1",
      // rightList: [
      //   { type: 1, message: "123123123123" },
      //   { type: 2, img: "123123123123" },
      // ],
      selectMaterItem:null
    };
  },
  props: {
    width:{
      default:"940px"
    },
    height:{
      default:'520px'
    },
    title: {
      type: String,
      default: "",
    },
    selectItem: {
      type: Object,
      default: null,
    },
    type:{
      default:""
    }
  },
  components: {
    MaterialList,
  },
  created() {
    if (this.selectItem) {
      this.text = this.selectItem.message;
    }
  },
  methods: {
    handleClose() {
      this.$emit("update:visable", false); //;
      this.$emit("close", this.type); //关闭弹窗;
    },

    handleClick() {},

    // 选中
    handleSelect(item) {
      // console.log(item);
      this.selectMaterItem = item
    },

    handleSubmit() {
      if (!this.text) {
        this.$message.warning("输入不能为空");
        return;
      }
      this.$emit("submit", this.text);
    },

    handleChecked(item){
      item.checked = !item.checked
      console.log(this.selectMaterItem)
    }
  },
};
</script>
<style lang="scss" scoped>
.titlex {
  line-height: 38px;
}
// .materbox {
//   height: 520px;
// }
.m_left {
  flex:1 1;
  // width: 550px;
}
.m_right {
  // flex: 1;
  width: 340px;
  height: 100%;
  overflow-y: auto;
  width: 390px;
  background: #fff;
  border-left: 1px solid #e9e9e9;
}
::v-deep .el-dialog__body {
  padding: 0;
}
::v-deep .el-tabs__nav-wrap::after {
  height: 1px;
}
::v-deep .el-tabs__nav-scroll {
  padding-left: 16px;
}
::v-deep .el-tabs__header {
  margin-bottom: 0;
}
.r_header {
  height: 42px;
  line-height: 42px;
  background-color: #f5f5f5;
  border-bottom: 1px solid #e9e9e9;
}
.chat-item {
  min-height: 60px;
}
.chat-dot {
  width: 40px;
  text-align: center;
  .dot {
    width: 20px;
    height: 20px;
    line-height: 20px;
    font-size: 12px;
    background: #ddd;
    border-radius: 50%;
    display: inline-block;
    text-align: center;
  }
}
.textitem {
  max-width: 270px;
  word-break: break-all;
  width: fit-content;
  padding: 6px 12px;
  color: #000;
  border: 1px solid #e9e9e9;
  border-radius: 5px;
}
.imgitem {
  display: block;
  max-width: 160px;
  max-height: 160px;
  cursor: pointer;
  border-radius: 5px;
}
</style>